package com.lesson02;

import java.awt.*;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class TestWindow {
    public static void main(String[] args) {
        new WindowFrame();
    }
}
class WindowFrame extends Frame{

    public WindowFrame(){
        setBackground(Color.BLUE);
        setBounds(300,200,200,150);
        setVisible(true);

        //addWindowListener(new WindowListener());
        this.addWindowListener(new WindowAdapter()
        {
            //匿名内部类
            //关闭窗口
            @Override
            public void windowClosing(WindowEvent e){
                System.out.println("关闭窗口");
                setVisible(false);//隐藏窗口
                System.exit(0);//正常退出
            }
            //激活窗口
            @Override
            public void windowActivated(WindowEvent e){
                WindowFrame source = (WindowFrame) e.getSource();
                source.setTitle("激活了");
                System.out.println("激活了");
            }
            //
            @Override
            public void windowDeactivated(WindowEvent e){
                WindowFrame source = (WindowFrame) e.getSource();
                source.setTitle("未激活");
                System.out.println("未激活");
            }
        });
    }
}